
var _i = 0;
var _custParams = "";
var _bActionStarted = false;
var _a = window.dialogArguments;
var _oXml = CreateXmlDocument(false);
_oXml.onreadystatechange = wait;
var __dialogXml = "";
var _xmlhttp = CreateXmlHttp();
var _xmlDoc = CreateXmlDocument(false);
var _submitUrl = "";
var _errorCode = ERROR_NONE;
var _errorNumber = "";
var _errorDescription = "";
var _errorCount = 0;
var _renderFillBar = true;
var _iStep = 0;

function go()
{
    _errorCode = ERROR_NONE;
    _errorCount = 0;
    _errorNumber = "";
    _errorDescription = "";

    butBegin.disabled			= true;

    PrepareFillBar();
    _bActionStarted = true;
    window.setTimeout("performAction()", 100);
}
function PrepareFillBar()
{
    divWarning.style.display	= "none";
    if (_renderFillBar)
    {
        var oHeader = document.getElementById("tdDialogHeader");
        var oFooter = document.getElementById("tdDialogFooter");
        var oFillBar = document.getElementById("divFillBg");

        alert(oFooter);
        var nHeaderHeight	= (oHeader == null) ? 0 : parseInt(oHeader.scrollHeight, 10);
        var nFooterHeight	= (oFooter == null) ? 0 : parseInt(oFooter.scrollHeight, 10);
        var nFillBarHeight	= (oFillBar == null) ? 0 : parseInt(oFillBar.style.height, 10);
        var nDialogHeight	= parseInt(window.dialogHeight, 10);


        var nVerticalPosition	= ((nDialogHeight - (nHeaderHeight + nFooterHeight)) / 2) + nHeaderHeight - (nFillBarHeight / 2);
        var nFillBarWidth		= parseInt(window.dialogWidth, 10) - 40;
        divFillBg.style.display		= "inline";
        divStatus.style.display		= "inline";
        divFill.style.display		= "inline";

        SetFillBarDimensions(divFillBg, nVerticalPosition, nFillBarWidth);
        SetFillBarDimensions(divFill, nVerticalPosition, 0);
        SetFillBarDimensions(divStatus, nVerticalPosition, nFillBarWidth);
        SetFillBarDimensions(divStatus.firstChild, 0, nFillBarWidth);

        _iStep = nFillBarWidth / _a.length;
    }
}

function SetFillBarDimensions(oDiv, nTop, nWidth)
{
    oDiv.style.top		= nTop;
    oDiv.style.width	= nWidth;
}
function wait()
{
    if (_oXml.readyState == 4)
    {
        var status = handleXMLErr(_oXml, true);
        if (status == ERROR_CONTINUE)
        {
            if (_errorCount == 0)
            {
                _errorCode = status;

                var codeNode = _oXml.selectSingleNode("/error/code");


                _errorNumber = (codeNode == null) ? 0x80004005 : codeNode.text;


                var descNode = _oXml.selectSingleNode("/error/description");
                _errorDescription = (IsNull(descNode) ? "" : descNode.text);
            }
            _errorCount++;
        }
        if (_i < (_a.length - 1))
        {
            divFill.style.pixelWidth = _iStep * (_i + 2);
            window.setTimeout("performAction()", 10);
        }
        else
        {
            if (_errorCode == ERROR_CONTINUE)
            {
                if (_errorCount == 1 && _a.length == 1)
                {
                    openErrorDlg(_errorNumber, _errorDescription);
                }
                else
                {
                    alert(LOCID_MULTIACTION_ERROR_FOUND);
                }
                window.returnValue = (_errorCount != _a.length);
            }
            else
            {
                window.returnValue = true;
            }

            if (IsOutlookClient())
            {
                if ((IsActivityTypeCode(_iObjType) || Contact == _iObjType || QueueItem == _iObjType) &&
                (typeof(dialogArguments.opener) != "undefined"))
                {
                    try
                    {
                        dialogArguments.opener.refreshGrid(dialogArguments.grid);
                    }
                    catch (e) {}
                }
            }
            window.close();
        }
    }
}
function performAction()
{
    if (__dialogXml == "")
    {
        __dialogXml = "<node />";
    }
    _xmlDoc.loadXML(__dialogXml);
    _submitUrl = prependOrgName("/_grid/cmds/dlg_") + _sAction + ".aspx?iObjType=" + _iObjType + "&iTotal=1&iIndex=" + _i + _custParams;
    if (_a)
    {
        _submitUrl += "&iId=" + _a[_i];
    }
    _xmlhttp.open("POST", _submitUrl, false);
    SetTokenInHeader(_xmlhttp, _submitUrl);
    _xmlhttp.send(_xmlDoc);
    _oXml.loadXML(_xmlhttp.responseXML.xml);
    _i++;
}
function cancel()
{
    if (_bActionStarted)
    {
        if (window.confirm( formatString(LOCID_CONFIRM_MULTI_CANCEL, (_a.length - _i)) ))
        {
            window.returnValue = true;
            window.close();
        }
    }
    else
    {
        window.close();
    }
}
